import modelExtend from '@/utils/modelExtend';
import HttpModel from './http';
import {doPostToObj, doPostParam} from '@/services/http'

let mileage = {
  namespace: 'mileage',
  state: {
    loading: true,
    rows: [],
    pagination: {
      current: 1,
      pageSize: 10,
      totle: 0
    }
  },
  effects: {
    //分页查询行驶里程列表
    *queryList ({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: { loading: true },
      })
      const response = yield call(doPostToObj, payload)
      yield put({
        type: 'save',
        payload: {
          loading: false,
          rows: response.data?.rows,
          pagination: response.data?.pagination
        },
      })
      if (callback) callback(response);
      return response;
    },
  },
  reducers: {
    save (state, action) {
      return {
        ...state,
        ...action.payload,
      }
    },
  },
}
mileage = modelExtend(HttpModel, mileage);
export default mileage;